<%@page import="java.security.interfaces.RSAKey"%>
<%@page import="org.jbit.news.dao.impl.TopicDaoImpl"%>
<%@page import="org.jbit.news.dao.impl.NewsDaoImpl"%>
<%@page import="org.jbit.news.entity.News"%>
<%@page import="org.jbit.news.biz.impl.NewsBizImpl"%>
<%@page import="org.jbit.news.biz.NewsBiz"%>
<%@page import="org.jbit.news.biz.impl.TopicBizImpl"%>
<%@page import="org.jbit.news.biz.TopicBiz"%>
<%@page import="org.jbit.news.entity.Topic"%>
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://"
	+ request.getServerName() + ":" + request.getServerPort()
	+ path + "/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">

<title>My JSP 'do_topic_add.jsp' starting page</title>

<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
	<link rel="stylesheet" type="text/css" href="styles.css">
	-->

</head>

<body>
	<%
		request.setCharacterEncoding("utf-8");
			response.setCharacterEncoding("utf-8");
			String opr = request.getParameter("opr");
			String tname = request.getParameter("tname");
			String tid =request.getParameter("tid");
			TopicBiz topicBiz = new TopicBizImpl();
			NewsBiz newsBiz=new NewsBizImpl();
			
	if (opr.equals("add")) {
		List<Topic> list = topicBiz.fingTopicByName(tname);
		if (list.size() < 1) {
			int num = topicBiz.addToipc(tname);
			request.getRequestDispatcher("../newspages/topic_list.jsp")
					.forward(request, response);

		}else{
			response.sendRedirect("../newspages/topic_list.jsp");
		}

			}else if(opr.equals("delTopic")){
		 
			
			int num=topicBiz.deleteTopic(Integer.parseInt(tid));
			if(num>0){
	%>
	<script type="text/javascript">
		alert("删除主题成功！点击确认返回列表")
		location.href = "../newspages/topic_list.jsp"
	</script>
	<%
		request.getRequestDispatcher("../newspages/topic_list.jsp").forward(request, response); 
			}
		else{
	%>
	<script type="text/javascript">
		alert("删除主题失败，请联系管理员！点击确认返回列表")
		location.href = "../newspages/topic_list.jsp"
	</script>


	<%
		response.sendRedirect("../newspages/topic_list.jsp");
			}
		} else if (opr.equals("update")) {
// 			String tname1 = request.getParameter("tname");
// 			String tid1 = request.getParameter("tid");
			Topic topic = new Topic();
			topic.setTname(tname);
			topic.setTid(Integer.parseInt(tid));
			int i=topicBiz.updateTopic(topic);
			if(i>0){
				
		response.sendRedirect("../newspages/topic_list.jsp");
			}else{
				response.sendRedirect("../newspages/topic_list.jsp");
			}

		}
	%>
</body>
</html>
